package com.oriental.manage.controller.settlement.clear.redo;

import com.oriental.clearDubbo.api.reserve.TransPushInterface;
import com.oriental.clearDubbo.model.base.CompanyModel;
import com.oriental.clearDubbo.model.base.ResponseModel;
import com.oriental.manage.core.response.ResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 重推结算数据到备付金系统
 * Created by zhangxinhai on 2017/2/28.
 */
@Slf4j
@Controller
@RequestMapping("settlement/clear/redo/redoTransPush")
public class RedoTransPushController {
    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private TransPushInterface transPushInterface;

    @RequestMapping("init")
    @RequiresPermissions("redoTransPush_search")
    public String init() {

        return "settlement/clear/redo/redoTransPush";
    }

    @RequiresPermissions("redoTransPush_search")
    @RequestMapping("redoMchntClearDay")
    @ResponseBody
    public ResponseDTO<String> redoMchntClearDay(String orgCode, String settleDate) {
        ResponseDTO<String> responseDTO = new ResponseDTO<String>();
        try {
            CompanyModel companyModel = new CompanyModel();
            companyModel.setCompanyCode(orgCode);
            companyModel.setSettleDate(settleDate);
            log.info("重推商户日结数据到备付金系统请求：{}",companyModel);
            ResponseModel responseModel = transPushInterface.redoMchntClearDay(companyModel);
            log.info("重推商户日结数据到备付金系统结果：{}",responseModel);
            if (responseModel.getIsSuccess()) {
                if(responseModel.getResponseResult()){
                    responseDTO.setSuccess(true);
                    responseDTO.setObject("操作成功");
                }else {
                    responseDTO.setSuccess(false);
                    responseDTO.setObject("操作失败");
                }
            } else {
                responseDTO.setSuccess(false);
                responseDTO.setMsg("系统繁忙");
            }
        } catch (Exception e) {
            log.error("重推商户日结数据到备付金系统异常", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("系统繁忙");
        }
        return responseDTO;
    }

    @RequiresPermissions("redoTransPush_search")
    @RequestMapping("redoPayClearDay")
    @ResponseBody
    public ResponseDTO<String> redoPayClearDay(String orgCode, String settleDate) {
        ResponseDTO<String> responseDTO = new ResponseDTO<String>();
        try {
            CompanyModel companyModel = new CompanyModel();
            companyModel.setCompanyCode(orgCode);
            companyModel.setSettleDate(settleDate);
            log.info("重推机构日结数据到备付金系统请求：{}",companyModel);
            ResponseModel responseModel = transPushInterface.redoPayClearDay(companyModel);
            log.info("重推机构日结数据到备付金系统结果：{}",responseModel);
            if (responseModel.getIsSuccess()) {
                if(responseModel.getResponseResult()){
                    responseDTO.setSuccess(true);
                    responseDTO.setObject("操作成功");
                }else {
                    responseDTO.setSuccess(false);
                    responseDTO.setObject("操作失败");
                }
            } else {
                responseDTO.setSuccess(false);
                responseDTO.setMsg("系统繁忙");
            }
        } catch (Exception e) {
            log.error("重推机构日结数据到备付金系统异常", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("系统繁忙");
        }
        return responseDTO;
    }

    @RequiresPermissions("redoTransPush_search")
    @RequestMapping("redoMchntClearDetail")
    @ResponseBody
    public ResponseDTO<String> redoMchntClearDetail(String handleBatchNo) {
        ResponseDTO<String> responseDTO = new ResponseDTO<String>();
        try {
            CompanyModel companyModel = new CompanyModel();
            companyModel.setCompanyCode(handleBatchNo);
            log.info("重推商户审核数据到备付金系统请求：{}",companyModel);
            ResponseModel responseModel = transPushInterface.redoMchntClearDetail(companyModel);
            log.info("重推商户申数据到备付金系统结果：{}",responseModel);
            if (responseModel.getIsSuccess()) {
                if(responseModel.getResponseResult()){
                    responseDTO.setSuccess(true);
                    responseDTO.setObject("操作成功");
                }else {
                    responseDTO.setSuccess(false);
                    responseDTO.setObject("操作失败");
                }
            } else {
                responseDTO.setSuccess(false);
                responseDTO.setMsg("系统繁忙");
            }
        } catch (Exception e) {
            log.error("重推商户申数据到备付金系统异常", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("系统繁忙");
        }
        return responseDTO;
    }

    @RequiresPermissions("redoTransPush_search")
    @RequestMapping("redoPayClearDetail")
    @ResponseBody
    public ResponseDTO<String> redoPayClearDetail(String handleBatchNo) {
        ResponseDTO<String> responseDTO = new ResponseDTO<String>();
        try {
            CompanyModel companyModel = new CompanyModel();
            companyModel.setCompanyCode(handleBatchNo);
            log.info("重推机构审核数据到备付金系统请求：{}",companyModel);
            ResponseModel responseModel = transPushInterface.redoPayClearDetail(companyModel);
            log.info("重推机构审核数据到备付金系统结果：{}",responseModel);
            if (responseModel.getIsSuccess()) {
                if(responseModel.getResponseResult()){
                    responseDTO.setSuccess(true);
                    responseDTO.setObject("操作成功");
                }else {
                    responseDTO.setSuccess(false);
                    responseDTO.setObject("操作失败");
                }
            } else {
                responseDTO.setSuccess(false);
                responseDTO.setMsg("系统繁忙");
            }
        } catch (Exception e) {
            log.error("重推机构审核数据到备付金系统异常", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("系统繁忙");
        }
        return responseDTO;
    }

}
